import { PoolManager } from '../managers/PoolManager';
import { Vector2, Vector3 } from '../utils/Math';

/**
 * PoolManager泛型池与PhysicsWorldManager集成测试
 */
export class PoolManagerTest {
    static runAll() {
        console.log('==== PoolManager 泛型池/物理世界管理器 测试开始 ====');
        PoolManagerTest.testBatchGetRelease();
        PoolManagerTest.testPoolLimit();
        PoolManagerTest.testAutoClear();
        console.log('==== PoolManager 泛型池/物理世界管理器 测试结束 ====');
    }

    /**
     * 测试批量获取/回收
     */
    static testBatchGetRelease() {
        const arr = PoolManager.instance.getGenericMany('TestObj', 5, () => ({ v: Math.random() }));
        console.assert(arr.length === 5, '批量获取数量应为5');
        PoolManager.instance.putGenericMany('TestObj', arr);
        const arr2 = PoolManager.instance.getGenericMany('TestObj', 5, () => ({ v: 0 }));
        console.assert(arr2.length === 5, '批量回收后再获取数量应为5');
        console.log('批量获取/回收测试通过');
    }

    /**
     * 测试池容量限制
     */
    static testPoolLimit() {
        PoolManager.instance.setGenericPoolLimit('TestLimit', 3);
        const objs = [{}, {}, {}, {}, {}];
        PoolManager.instance.putGenericMany('TestLimit', objs);
        const pool = (PoolManager.instance as any).genericPools.get('TestLimit');
        console.assert(pool.length === 3, '池容量限制应为3');
        PoolManager.instance.setGenericPoolLimit('TestLimit', 100); // 恢复
        PoolManager.instance.clearGenericPool('TestLimit');
        console.log('池容量限制测试通过');
    }

    /**
     * 测试自动清理
     */
    static testAutoClear() {
        PoolManager.instance.putGeneric('TestAuto', { a: 1 });
        // 模拟时间流逝
        (PoolManager.instance as any).genericPoolLastUsed.set('TestAuto', Date.now() - 120000);
        PoolManager.instance.autoClearUnusedGenericPools(60000);
        const pool = (PoolManager.instance as any).genericPools.get('TestAuto');
        console.assert(!pool || pool.length === 0, '自动清理应清空长时间未用池');
        console.log('自动清理测试通过');
    }

    
}

